#!/usr/bin/env python
#coding=utf-8
#check network state
import os, subprocess, platform

def checknetconn():
    fnull = open(os.devnull, 'w')
    ipaddress='202.101.172.35'
    if platform.system()=='Windows':
        cmd='ping %s -n 3' % ipaddress
    else:       #Linux
        cmd='ping %s -c 3' % ipaddress
    ret = subprocess.call(cmd, shell=True, stdout = fnull, stderr = fnull)
    fnull.close()
    if ret:
        return False
    else:
        return True

if __name__=='__main__':
    if checknetconn():
        print 'ping ok'
    else:
        print 'ping fail'
